@extends('admin.layout')
@section('title','首页')
@section('content1')
    <div class="col-sm-9 col-sm-offset-3 col-md-10 col-md-offset-2 main">
        <div class="col-md-12" id="content">
            <div class="app_content_div" id="app_content_div_301Index">
                <h3>管理员用户列表</h3>
            </div>
            <div>
        <div style="float:right;">
            <button type="button" class="btn btn-primary" onclick="window.location.href='/adm/user/add-user'">添加管理员</button>
        </div>
    </div><form action="/adm/user/del-user" method="post">
    <table class="table table-striped">

        @csrf
        <thead>
        <tr>
            <th>id</th>
            <th>用户名</th>
            <th>更改密码</th>
            <th>删除<th>
        </tr>
        </thead>
        <tbody>
        @foreach($oUsers as $v)
        <tr>
            <th id="user_id" scope="row">{{$v->id}}</th>
            <td>{{$v->name}}</td>
            <td><a style="cursor:pointer;" href="/adm/user/edit-user/{{$v->id}}">更改密码</a></td>
            <td>
                <a onclick="delUser({{$v->id}})"><span class="glyphicon glyphicon-trash" aria-hidden="true"></span></a>
            </td>
        </tr>
        @endforeach
        </tbody></table></form>
            {{$oUsers->links('admin.page')}}
        </div>
    </div>


    <script type="text/javascript" language="javascript">
        function delUser(id)
        {

            if(id===1||id===2||id===3)
            {
                alert("不能删除制作者");
                return;
            }
            if(id==={{Auth::user()->id}}){
                alert("不能删除自己！");
                return;
            }
            var r = confirm("确认删除吗？这个过程不可逆！");
            if( r === true )
            {
                var url="/adm/user/del-user";
                var token="{{@csrf_token()}}";
                $.post(url,{'_token':token,'id':id},function(data){
                    alert('已删除');
                    location.reload();
                });
            }
        }
    </script>
@endsection
